export class ConfigUtils {
/**
 * 配置合并（忽略 undefined 值）
 */
  static mergeConfig<T extends Record<string, any>>(
    defaultConfig: T,
    userConfig: Partial<T>,
    options?: {
      ignoreUndefined: boolean
    },
  ): T {
    const { ignoreUndefined = true } = options || {}
    const result = { ...defaultConfig }

    for (const key in userConfig) {
      if (ignoreUndefined && userConfig[key] === undefined)
        continue

      result[key] = userConfig[key]!
    }

    return result
  }

  /**
   * 查找重复项
   */
  static findDuplicateItems<T>(items: T[]): T[] {
    const seen = new Set<T>()
    const duplicates = new Set<T>()

    items.forEach((item) => {
      if (seen.has(item)) {
        duplicates.add(item)
      }
      else {
        seen.add(item)
      }
    })

    return Array.from(duplicates)
  }

  /**
   * 从对象中移除指定键
   */
  static removeKeys<T extends Record<string, any>, K extends keyof T>(
    obj: T,
    ...keysToRemove: K[]
  ): Omit<T, K> {
    const result = { ...obj }
    keysToRemove.forEach((key) => {
      delete result[key]
    })
    return result
  }
}
